You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
import { users } from "drizzle-pkg/lib/schema/auth";
|
|
import { and, eq } from "drizzle-orm";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const publicSlug = event.context.params?.publicSlug;
|
|
if (!publicSlug || typeof publicSlug !== "string") {
|
|
throw createError({ statusCode: 400, statusMessage: "无效主页" });
|
|
}
|
|
|
|
const [owner] = await dbGlobal
|
|
.select()
|
|
.from(users)
|
|
.where(and(eq(users.publicSlug, publicSlug), eq(users.status, "active")))
|
|
.limit(1);
|
|
|
|
if (!owner) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
|
|
const bioOk = owner.bioVisibility === "public" && Boolean(owner.bioMarkdown?.trim());
|
|
if (!bioOk) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
|
|
return R.success({
|
|
user: {
|
|
publicSlug: owner.publicSlug,
|
|
nickname: owner.nickname,
|
|
avatar: owner.avatarVisibility === "public" ? owner.avatar : null,
|
|
},
|
|
bio: { markdown: owner.bioMarkdown as string },
|
|
});
|
|
});
|
|
|